package gulimall.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author HLF
 * @date 2022/7/28 14:17
 */
@Configuration
public class MyThreadConfig {
    @Resource
    private ThreadPoolProperties threadPoolProperties;


    @Bean
    public ThreadPoolExecutor executor() {
        return new ThreadPoolExecutor(threadPoolProperties.getCoreSize(), threadPoolProperties.getMaxSize(),
                threadPoolProperties.getKeepAliveTime(), TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(10000), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }

}
